package com.qc.service.impl;

import com.qc.service.WeChatService;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

//@Service
//public class WeChartServiceimpl implements WeChatService {
//
//    @Override
//    public String codetoopenid(String code) {
//        Map<String, String> data = new HashMap<String, String>();
//        data.put("appid", "++++++++++++");
//        data.put("secret", "----------");
//        data.put("js_code", code);
//        data.put("grant_type", "authorization_code");
//
//        String response = HttpRequest.get("https://api.weixin.qq.com/sns/jscode2session").form(data).body();
//        System.out.println("Response was: " + response);
//        JSONObject obj= JSON.parseObject(response);//将json字符串转换为json对
//        System.out.println(obj);
//        return null;
//    }
//}

@Service
public class WeChartServiceimpl implements WeChatService {

    @Override
    public String codetoopenid(String code) {
        RestTemplate restTemplate = new RestTemplate();
        String url = "https://api.weixin.qq.com/sns/jscode2session?appid=wx77a1b8a8d78d160e&secret=7f43dc99c22726918fcabf2ad16aa007&js_code=" + code + "&grant_type=authorization_codek" ;
        String forObject = restTemplate.getForObject(url, String.class);
        System.out.println(forObject);
        return forObject;
    }
}